//
//  String+Localize.swift
//  GT FM Radio
//
//  Created by macmini01 on 2024/8/9.
//


import Foundation

extension String {
    public var localized: String {
        return self.localized()
    }
}

extension String {
    public var localeDisplayName: String {
        let locale : NSLocale = NSLocale(localeIdentifier: self)
        if let displayName = locale.displayName(forKey: NSLocale.Key.identifier, value: self) {
            return displayName
        }
        return self
    }
}

extension String {
    public func containsEmoji() -> Bool {
        let emojiPatern = #"[^\p{L}^\p{N}^\p{P}^\p{Z}]"#
        let regex = try! NSRegularExpression(pattern: emojiPatern, options: [])
        let matchs = regex.matches(in: self, range: NSRange(location: 0, length: self.utf16.count))
        return !matchs.isEmpty
    }
    
}

extension Int {
    public var localeString: String {
        let numformater = NumberFormatter.shared
        numformater.locale = Locale(identifier: Locale.currentLanguage())
        return numformater.string(from: NSNumber(integerLiteral: self)) ?? "\(self)"
    }
}

extension NumberFormatter {
    static let shared = NumberFormatter()
}


